(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/Script/gameEvent/TouchEvent.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, 'ee699pW801OLZ3I5XBLMrYm', 'TouchEvent', __filename);
// Script/gameEvent/TouchEvent.ts

Object.defineProperty(exports, "__esModule", { value: true });
var autoFixed_1 = require("./autoFixed");
// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html
var Constant_1 = require("../constant/Constant");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var TouchEvent = /** @class */ (function (_super) {
    __extends(TouchEvent, _super);
    function TouchEvent() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.fatherNode = null;
        return _this;
        // update (dt) {}
    }
    /**
     * 当点击触发时
     */
    TouchEvent.prototype.touchStart = function () {
        var halfScreen = Constant_1.Constant.SCREEN.width / 2;
        var control = this.fatherNode.getComponent(autoFixed_1.default);
        var touchCnt = [];
        this.node.on(cc.Node.EventType.TOUCH_START, function (touch) {
            var cnt = 0;
            var id = touch.getID();
            if (id >= 2)
                return;
            touchCnt[id] = touch;
            touchCnt.forEach(function (e) {
                if (e != null)
                    cnt++;
            });
            switch (cnt) {
                case 1: //单点
                    if (touch.getLocationX() > halfScreen) { //右半
                        //  cc.log("右边");
                        control.allToRight();
                    }
                    else { //左半
                        // cc.log("左边");
                        control.allToLeft();
                    }
                    break;
                case 2: //两点
                    var fingerTwoSide_one = touchCnt[0].getLocationX() > halfScreen && touchCnt[1].getLocationX() < halfScreen;
                    var fingerTwoSide_two = touchCnt[1].getLocationX() > halfScreen && touchCnt[0].getLocationX() < halfScreen;
                    var fingerOneLeft = touchCnt[0].getLocationX() < halfScreen && touchCnt[1].getLocationX() < halfScreen;
                    if (fingerTwoSide_one || fingerTwoSide_two) {
                        control.splitOver();
                    }
                    else {
                        if (fingerOneLeft) { //两个触点都在左边
                            control.allToLeft();
                        }
                        else {
                            control.allToRight();
                        }
                    }
                    break;
                default: break; //三个以上不作处理
            }
        });
        this.node.on(cc.Node.EventType.TOUCH_END, function (touch) {
            var id = touch.getID();
            touchCnt[id] = null;
            var cnt = 0;
            touchCnt.forEach(function (e) {
                if (e != null)
                    cnt++;
            });
            switch (cnt) {
                case 0: //手指全部离开屏幕
                    control.autoFixed();
                    break;
                case 1: //有一只手指
                    {
                        if (id == 0) { //右边屏幕持续按压
                            if (touchCnt[1].getLocationX() > halfScreen) { //右半
                                //  cc.log("右边");
                                control.allToRight();
                            }
                            else { //左半
                                // cc.log("左边");
                                control.allToLeft();
                            }
                        }
                        else {
                            if (touchCnt[0].getLocationX() > halfScreen) { //右半
                                //  cc.log("右边");
                                control.allToRight();
                            }
                            else { //左半
                                // cc.log("左边");
                                control.allToLeft();
                            }
                        }
                        break;
                    }
            }
        });
    };
    TouchEvent.prototype.onLoad = function () {
        this.touchStart(); //注册点击事件
    };
    TouchEvent.prototype.start = function () {
    };
    __decorate([
        property(cc.Node)
    ], TouchEvent.prototype, "fatherNode", void 0);
    TouchEvent = __decorate([
        ccclass
    ], TouchEvent);
    return TouchEvent;
}(cc.Component));
exports.default = TouchEvent;

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=TouchEvent.js.map
        